// Imports
import java.awt.*;
import java.awt.event.*;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import javax.swing.*;

class SimpleTableExample
		extends 	JFrame
 {
	// Instance attributes used in this example
	private	JPanel		topPanel;
	private	JTable		table;
	private	JScrollPane scrollPane;

	// Constructor of main frame
	public SimpleTableExample() throws SQLException
	{
		// Set the frame characteristics
		setTitle( "Utility Table" );
		setSize( 300, 200 );
		setBackground( Color.gray );

		// Create a panel to hold all other components
		topPanel = new JPanel();
		topPanel.setLayout( new BorderLayout() );
		getContentPane().add( topPanel );

		// Create columns names
		String columnNames[] = { "port", "ipaddr", "duration" };

		ResultSet rs=Queries.select("select * from utility");
		String dataValues[][] =new String[25][25];
		int i=0,j=0;
		ResultSetMetaData rm=rs.getMetaData();
		while(rs.next())
		{
			int k=0;
			for(j=1;j<=rm.getColumnCount();j++)
			{
				dataValues[i][k]=rs.getString(j);
			k++;
			}
			i++;
		}
		
		
		// Create some data
//		String dataValues[][] =
//		{
//			{ "12", "234", "67" },
//			{ "-123", "43", "853" },
//			{ "93", "89.2", "109" },
//			{ "279", "9033", "3092" }
//		};

		// Create a new table instance
		table = new JTable( dataValues, columnNames );
		
		// Add the table to a scrolling pane
		scrollPane = new JScrollPane( table );
		topPanel.add( scrollPane, BorderLayout.CENTER );
	}

	// Main entry point for this example
	public static void showTable() throws SQLException
	{
		// Create an instance of the test application
		SimpleTableExample mainFrame	= new SimpleTableExample();
		mainFrame.setVisible( true );
	}
}